package state.person;

import static org.junit.Assert.*;

import org.junit.Test;

import state.group.ElevatorStruct;
import state.group.HallCall;

public class PersonTest {

    @Test
    public void testEquals()
    {
        
        HallCall call1 = new HallCall((byte) 20, ElevatorStruct.DOWN);
        HallCall call2 = new HallCall((byte) 20, ElevatorStruct.UP);
        
        Person p1 = new Person("Joe", PersonType.Basic, 100, call1, (byte) 4);
        Person p2 = new Person("JoeBoB", PersonType.Basic, 100, call1, (byte) 4);
        Person p3 = new Person("Joe", PersonType.Basic, 100, call1, (byte) 3);
        Person p4 = new Person("Joe", PersonType.Basic, 100, call2, (byte) 4);
        Person p5 = new Person("Joe", PersonType.Basic, 150, call1, (byte) 4);
        Person p6 = new Person("Joe", PersonType.Dummy, 100, call1, (byte) 4);
        Person p7 = new Person("JoeBN", PersonType.Basic, 120, call2, (byte) 8);
        Person p8 = new Person("Joe", PersonType.Basic, 100, call1, (byte) 4);
        
        assertEquals(p1, p1);
        
        assertEquals(p1, p8);
        assertEquals(p8, p1);
        
        p8.setCurrentElevatorId((byte) 3);
        assertFalse(p1.equals(p8));
        assertFalse(p8.equals(p1));
        
        p8.setCurrentElevatorId((byte) 0);
        assertEquals(p1, p8);
        assertEquals(p8, p1);
        
        p8.setState(PersonState.goingOut);
        assertFalse(p1.equals(p8));
        assertFalse(p8.equals(p1));
        
        assertFalse(p1.equals(p2));
        assertFalse(p2.equals(p1));
        
        assertFalse(p1.equals(p3));
        assertFalse(p3.equals(p1));
        
        assertFalse(p1.equals(p4));
        assertFalse(p4.equals(p1));
        
        assertFalse(p1.equals(p5));
        assertFalse(p5.equals(p1));
        
        assertFalse(p1.equals(p6));
        assertFalse(p6.equals(p1));
        
        assertFalse(p1.equals(p7));
        assertFalse(p7.equals(p1));
    }
    
    @Test
    public void testHashCode()
    {
        
        HallCall call1 = new HallCall((byte) 20, ElevatorStruct.DOWN);
        HallCall call2 = new HallCall((byte) 20, ElevatorStruct.UP);
        
        Person p1 = new Person("Joe", PersonType.Basic, 100, call1, (byte) 4);
        Person p2 = new Person("JoeBoB", PersonType.Basic, 100, call1, (byte) 4);
        Person p3 = new Person("Joe", PersonType.Basic, 100, call1, (byte) 3);
        Person p4 = new Person("Joe", PersonType.Basic, 100, call2, (byte) 4);
        Person p5 = new Person("Joe", PersonType.Basic, 150, call1, (byte) 4);
        Person p6 = new Person("Joe", PersonType.Dummy, 100, call1, (byte) 4);
        Person p7 = new Person("JoeBN", PersonType.Basic, 120, call2, (byte) 8);
        Person p8 = new Person("Joe", PersonType.Basic, 100, call1, (byte) 4);
        
        assertEquals(p1.hashCode(), p1.hashCode());
        
        assertEquals(p1.hashCode(), p8.hashCode());
        
        p8.setCurrentElevatorId((byte) 3);
        assertFalse(p1.hashCode() == p8.hashCode());
        
        p8.setCurrentElevatorId((byte) 0);
        assertEquals(p1.hashCode(), p8.hashCode());
        
        p8.setState(PersonState.inside);
        assertFalse(p1.hashCode() == p8.hashCode());
        
        assertFalse(p1.hashCode() == p2.hashCode());
        assertFalse(p1.hashCode() == p3.hashCode());
        assertFalse(p1.hashCode() == p4.hashCode());
        assertFalse(p1.hashCode() == p5.hashCode());
        assertFalse(p1.hashCode() == p6.hashCode());
        assertFalse(p1.hashCode() == p7.hashCode());
    }

}
